package main

import (
	"html/template"
	"net/http"

	"github.com/gin-gonic/gin"
)

func SetupRouter() *gin.Engine {
	router := gin.Default()
	router.SetFuncMap(template.FuncMap{
		"inc": func(i int) int { return i + 1 },
	})
	router.LoadHTMLGlob("templates/*")
	router.Static("css", "asset/css")

	router.POST("/favorite/add", AddFavorite)
	router.GET("/favorite", ListFavorites)
	router.POST("/favorite/delete", DeleteFavorite)

	// 其他路由配置
	router.GET("/index", Query)
	router.GET("/recycle_bin", ShowRecycleBin)
	router.POST("/add", Add)
	router.POST("/delete_one_row", DeleteOneRow)
	router.POST("/update", Update)
	router.GET("/search", SearchByIDHandler)
	router.GET("/edit", EditPage)
	router.POST("/login", Login)
	router.POST("/register", Register)
	router.POST("/check-username", CheckUsername)

	// 定义恢复学生的路由
	router.POST("/recycle_bin/restore/:id", RestoreStudent)

	// 定义永久删除学生的路由
	router.DELETE("/recycle_bin/delete/:id", PermanentDeleteStudent)

	router.POST("/share/delete", deleteShareHandler)
	router.POST("/share", ShareStudent)
	router.GET("/share", ShareStudent1)
	router.GET("/share_list", ShowShares)

	router.GET("/login", func(c *gin.Context) {
		c.HTML(http.StatusOK, "login.html", gin.H{})
	})
	router.GET("/register", func(c *gin.Context) {
		c.HTML(http.StatusOK, "register.html", gin.H{})
	})
	router.GET("/add", func(c *gin.Context) {
		c.HTML(http.StatusOK, "add.html", gin.H{})
	})
	router.GET("/update", func(c *gin.Context) {
		c.HTML(http.StatusOK, "update.html", gin.H{})
	})
	router.GET("/search.html", func(c *gin.Context) {
		c.HTML(http.StatusOK, "search.html", gin.H{})
	})
	return router
}
